import os
import requests
import re
import datetime

nowtime=datetime.datetime.now()
s0=str(nowtime.year)
st='0'
s1=str(nowtime.month)
if nowtime.month<10 :
    s1=st+s1
s2=str(nowtime.day)
sFinal=s0+'/'+s1+s2
sFinal2=s0+'/'+s1+'/'+s2

#到此为止是在把时间转换为学校网站用到的格式

urJW='https://jwc.nankai.edu.cn/'
respondsJW=requests.get(urJW)
JWtext=respondsJW.text.encode('iso-8859-1').decode('utf-8')

sPJW=sFinal+'.*?title=(.*?)>'

patternJW = re.compile(sPJW,re.S)
searchedJWText=re.findall(patternJW,JWtext)

#这里是在获取教务处是否更新

urZY='https://zyfw.nankai.edu.cn/index/huodong.aspx'
respondsZY=requests.get(urZY)
ZYtext=respondsZY.text#.encode('iso-8859-1').decode('utf-8')
sPZY='status2.*?\n.*?<.*?<'
patternZY = re.compile(sPZY,re.S)
tsearchedZYText=re.findall(patternZY,ZYtext)
patternZYDel='aspx.*?<'
searchedZYText=tsearchedZYText
for i in range(0,len(tsearchedZYText)):
    searchedZYText[i]=re.findall(patternZYDel,tsearchedZYText[i])
#获取志愿网站可报名的信息

urJSJ='https://cc.nankai.edu.cn/'
respondsJSJ=requests.get(urJSJ)
JSJtext=respondsJSJ.text.encode('iso-8859-1').decode('utf-8')
sPJSJ=sFinal+".*?\n.*?\n.*?newline.*?span>"
patternJSJ = re.compile(sPJSJ,re.S)
tsearchedJSJText=re.findall(patternJSJ,JSJtext)
sPJSJ2 ='line.*?>.*?>'
patternJSJ2 = re.compile(sPJSJ2,re.S)
searchedJSJText=tsearchedJSJText
for i in range(0,len(tsearchedJSJText)):
    searchedJSJText[i]=re.findall(patternJSJ2,tsearchedJSJText[i])



urNKmain='https://www.nankai.edu.cn/main.htm'
respondsMAIN=requests.get(urNKmain)
MAINtext=respondsMAIN.text.encode('iso-8859-1').decode('utf-8')
sMAIN=sFinal2+".*?<"
patternMAIN = re.compile(sMAIN,re.S)
tsearchedMAINText=re.findall(patternMAIN,MAINtext)
sPMAIN2 ='=".*?<'
patternMAIN2 = re.compile(sPMAIN2,re.S)
searchedMAINText=tsearchedMAINText
for i in range(0,len(tsearchedMAINText)):
    searchedMAINText[i]=re.findall(patternMAIN2,tsearchedMAINText[i])



if len(searchedJWText)==0:
    print("教务处今天没更新      "+'\n')
for i in searchedJWText:
    print (i+'\n')
print("当前信息来自教务处   " + str(datetime.datetime.now()) + '\n' + '\n')


if len(searchedZYText) == 0:
     print("目前没有可报名的志愿服务      "+'\n')
for i in range(0,len(searchedZYText)):
    print(searchedZYText[i][0]+'可报名'+'\n')
print("当前信息来自志愿服务网站   " + str(datetime.datetime.now()) + '\n' + '\n')


if len(searchedJSJText) == 0:
      print("计算机学院官网今天没更新      "+'\n')
for i in range(0, len(searchedJSJText)):
     print(searchedJSJText[i][0]+'\n')
print("当前信息来自计算机学院   " + str(datetime.datetime.now()) + '\n' + '\n')

if len(searchedMAINText) == 0:
      print("学校官网今天没更新      "+'\n')
for i in range(0, len(searchedMAINText)):
     print(searchedMAINText[i][0]+'\n')
print("当前信息来自学校官网   " + str(datetime.datetime.now()) + '\n' + '\n')

os.system("pause")